/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * test.java
 *
 * Created on 2012-02-28, 15.36.27
 */

package main;
import java.awt.*;
/**
 *
 * @author Mantas, Ramūnas, Vilius
 */
public class Main extends javax.swing.JFrame implements Runnable {

    private Thread runGUI = new Thread(this);
    private int sleepTime = 200;
    public void run(){
        while(true){
            this.repaint();
            VirtualMachine.updateRowCount();
            Stack.updateRowCount();
            
            showMode.setText(Processor.getMODE().toString());
            showSF.setText(Processor.getSF());
            showVirtualSF.setText(Processor.getSF());
            showIP.setText(Processor.getIP());
            showVirtualIP.setText(VirtualMachine.getIP());
            showSP.setText(Processor.getSP());
            showVirtualSP.setText(Stack.getSP());
            showPTR.setText(Processor.getPTR().toString());
            showSPTR.setText(Processor.getSPTR().toString());
            showPI.setText(Processor.getPI().toString());
            showSI.setText(Processor.getSI().toString());
            showTI.setText(Processor.getTI().toString());
            showTIMER.setText(Processor.getTIMER().toString());
            InOut.setText(Processor.getInOut().toString());
            try{
                this.runGUI.sleep(sleepTime);
            }
            catch(Exception e){
                System.out.println(e);
            }
        }
    }

    public Main() {
        //ZF, AF, OF, BF
        Processor.setSF("0000");
        Processor.setIP("0000");
        Processor.setSP("0000");
        Processor.setMODE(0);
        Processor.setPTR(0);
        Processor.setSPTR(0);
        Processor.setTIMER(0);
        Processor.setPI(0);
        Processor.setSI(0);
        Processor.setTI(0);
        VirtualMachine.setIP("0000");
        Stack.setSP("0000");
        initComponents();
        
        try{
            runGUI.start();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        processorPanel = new javax.swing.JPanel();
        MODE = new javax.swing.JLabel();
        showPTR = new javax.swing.JTextField();
        showPI = new javax.swing.JTextField();
        showMode = new javax.swing.JTextField();
        TIMER = new javax.swing.JLabel();
        PTR = new javax.swing.JLabel();
        showSI = new javax.swing.JTextField();
        TI = new javax.swing.JLabel();
        showTIMER = new javax.swing.JTextField();
        PI = new javax.swing.JLabel();
        showIP = new javax.swing.JTextField();
        processor = new javax.swing.JLabel();
        SI = new javax.swing.JLabel();
        IP = new javax.swing.JLabel();
        showTI = new javax.swing.JTextField();
        SF = new javax.swing.JLabel();
        showSF = new javax.swing.JTextField();
        showSP = new javax.swing.JTextField();
        AX3 = new javax.swing.JLabel();
        showSPTR = new javax.swing.JTextField();
        SPTR = new javax.swing.JLabel();
        memoryPanel = new javax.swing.JPanel();
        memory = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        memoryTable = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        virtualMemoryTable = new javax.swing.JTable();
        memory1 = new javax.swing.JLabel();
        memory2 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        StackTable = new javax.swing.JTable();
        processorPanel1 = new javax.swing.JPanel();
        showVirtualIP = new javax.swing.JTextField();
        processor1 = new javax.swing.JLabel();
        IP1 = new javax.swing.JLabel();
        SF1 = new javax.swing.JLabel();
        showVirtualSF = new javax.swing.JTextField();
        AX2 = new javax.swing.JLabel();
        showVirtualSP = new javax.swing.JTextField();
        loadAndSyntax = new javax.swing.JButton();
        step = new javax.swing.JButton();
        randomButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        InOut = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("mainWindow");

        MODE.setText("MODE");

        showPTR.setColumns(2);
        showPTR.setEditable(false);
        showPTR.setText("00");

        showPI.setEditable(false);
        showPI.setText("0");

        showMode.setEditable(false);
        showMode.setText("TRUE");
        showMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showModeActionPerformed(evt);
            }
        });

        TIMER.setText("TIMER");

        PTR.setText("PTR");

        showSI.setEditable(false);
        showSI.setText("0");

        TI.setText("TI");

        showTIMER.setColumns(4);
        showTIMER.setEditable(false);
        showTIMER.setText("0000");
        showTIMER.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showTIMERActionPerformed(evt);
            }
        });

        PI.setText("PI");

        showIP.setEditable(false);
        showIP.setText("0000");

        processor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        processor.setText("Processor");

        SI.setText("SI");

        IP.setText("IP");

        showTI.setEditable(false);
        showTI.setText("0");

        SF.setText("SF");

        showSF.setEditable(false);
        showSF.setText("000");

        showSP.setEditable(false);
        showSP.setText("0000");
        showSP.setName(""); // NOI18N
        showSP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showSPActionPerformed(evt);
            }
        });

        AX3.setText("SP");

        showSPTR.setColumns(2);
        showSPTR.setEditable(false);
        showSPTR.setText("00");

        SPTR.setText("SPTR");

        javax.swing.GroupLayout processorPanelLayout = new javax.swing.GroupLayout(processorPanel);
        processorPanel.setLayout(processorPanelLayout);
        processorPanelLayout.setHorizontalGroup(
            processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, processorPanelLayout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(processor)
                    .addGroup(processorPanelLayout.createSequentialGroup()
                        .addComponent(AX3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(showSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(processorPanelLayout.createSequentialGroup()
                        .addComponent(PTR)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showPTR, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, processorPanelLayout.createSequentialGroup()
                            .addComponent(TI)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(showTI))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, processorPanelLayout.createSequentialGroup()
                            .addComponent(SI)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(showSI))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, processorPanelLayout.createSequentialGroup()
                            .addComponent(PI)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(showPI, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(processorPanelLayout.createSequentialGroup()
                        .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TIMER)
                            .addComponent(SF))
                        .addGap(4, 4, 4)
                        .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(showTIMER, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(showSF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, processorPanelLayout.createSequentialGroup()
                            .addComponent(MODE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(showMode, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(35, 35, 35))
                        .addGroup(processorPanelLayout.createSequentialGroup()
                            .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(processorPanelLayout.createSequentialGroup()
                                    .addComponent(IP)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(showIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(processorPanelLayout.createSequentialGroup()
                                    .addComponent(SPTR)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(showSPTR, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(51, 51, 51)))))
        );
        processorPanelLayout.setVerticalGroup(
            processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(processorPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(processor)
                .addGap(18, 18, 18)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(showPTR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PTR)
                    .addComponent(showSPTR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SPTR))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AX3)
                    .addComponent(showSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(IP))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PI)
                    .addComponent(showPI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MODE)
                    .addComponent(showMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SI)
                    .addComponent(showSI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TIMER)
                    .addComponent(showTIMER, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TI)
                        .addComponent(showTI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, processorPanelLayout.createSequentialGroup()
                        .addGroup(processorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(SF)
                            .addComponent(showSF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );

        memory.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        memory.setText("Memory");

        Memory.initTable();
        memoryTable.setFont(font);
        memoryTable.setModel(tableManager);
        memoryTable.setToolTipText("");
        memoryTable.setColumnSelectionAllowed(true);
        memoryTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        memoryTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(memoryTable);
        memoryTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        virtualMemoryTable.setFont(font);
        virtualMemoryTable.setModel(virtualTableManager);
        virtualMemoryTable.setModel(virtualTableManager);
        virtualMemoryTable.setColumnSelectionAllowed(true);
        virtualMemoryTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(virtualMemoryTable);
        virtualMemoryTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        memory1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        memory1.setText("Virtual Memory");

        memory2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        memory2.setText("Stack");

        StackTable.setFont(font);
        StackTable.setModel(stackTableManager);
        StackTable.setModel(stackTableManager);
        StackTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane4.setViewportView(StackTable);
        StackTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        javax.swing.GroupLayout memoryPanelLayout = new javax.swing.GroupLayout(memoryPanel);
        memoryPanel.setLayout(memoryPanelLayout);
        memoryPanelLayout.setHorizontalGroup(
            memoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(memoryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(memoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(memory))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(memoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(memory1)
                    .addComponent(memory2)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
                    .addComponent(jScrollPane4)))
        );
        memoryPanelLayout.setVerticalGroup(
            memoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(memoryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(memoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(memory)
                    .addComponent(memory1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(memoryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
                    .addGroup(memoryPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(memory2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        showVirtualIP.setEditable(false);
        showVirtualIP.setText("0000");

        processor1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        processor1.setText("Virtual Processor");

        IP1.setText("IP");

        SF1.setText("SF");

        showVirtualSF.setEditable(false);
        showVirtualSF.setText("000");

        AX2.setText("SP");

        showVirtualSP.setEditable(false);
        showVirtualSP.setText("0000");
        showVirtualSP.setName(""); // NOI18N

        javax.swing.GroupLayout processorPanel1Layout = new javax.swing.GroupLayout(processorPanel1);
        processorPanel1.setLayout(processorPanel1Layout);
        processorPanel1Layout.setHorizontalGroup(
            processorPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(processorPanel1Layout.createSequentialGroup()
                .addGroup(processorPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(processorPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(processorPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(processorPanel1Layout.createSequentialGroup()
                                .addComponent(AX2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(showVirtualSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(5, 5, 5)
                                .addComponent(IP1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(showVirtualIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(processorPanel1Layout.createSequentialGroup()
                                .addComponent(SF1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(showVirtualSF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(processorPanel1Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(processor1)))
                .addContainerGap(53, Short.MAX_VALUE))
        );
        processorPanel1Layout.setVerticalGroup(
            processorPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(processorPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(processor1)
                .addGap(18, 18, 18)
                .addGroup(processorPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(showVirtualSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AX2)
                    .addComponent(showVirtualIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(IP1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(processorPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(showVirtualSF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SF1))
                .addGap(69, 69, 69))
        );

        loadAndSyntax.setText("Load & Syntax");
        loadAndSyntax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadAndSyntaxActionPerformed(evt);
            }
        });

        step.setText("Step");
        step.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stepActionPerformed(evt);
            }
        });

        randomButton.setText("Run");
        randomButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                randomButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Spausdintuvas");

        InOut.setColumns(20);
        InOut.setRows(5);
        InOut.setEditable(false);
        jScrollPane3.setViewportView(InOut);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 13, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(processorPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(processorPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(randomButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(step))
                            .addComponent(loadAndSyntax)
                            .addComponent(jLabel1)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addComponent(memoryPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(memoryPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(processorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(step)
                            .addComponent(randomButton))
                        .addGap(18, 18, 18)
                        .addComponent(processorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(loadAndSyntax)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void randomButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_randomButtonActionPerformed
        Processor.setStep(0);
        Processor.setMODE(0);
        Parser.runProgram();
    }//GEN-LAST:event_randomButtonActionPerformed

    private void loadAndSyntaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadAndSyntaxActionPerformed
        Parser.readFromFile();
        Parser.pushed=false;
        System.out.println("row count: "+VirtualMachine.memoryNeeded);
        virtualMemoryTable.tableChanged(null);
    }//GEN-LAST:event_loadAndSyntaxActionPerformed

    private void stepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stepActionPerformed
        //Processor.setMODE(1);
        //Patikrinti IP ir i pradzia nuei
        Processor.setStep(1);
        Parser.runProgram();
        if(Processor.getPI() != 3)
        {
            VirtualMachine.increaseIP();
            PagingMechanism.convertVirtualIPToReal();
        }
    }//GEN-LAST:event_stepActionPerformed

    private void showSPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_showSPActionPerformed

    private void showTIMERActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showTIMERActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_showTIMERActionPerformed

    private void showModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showModeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_showModeActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }
    private TableManager tableManager = new TableManager();
    private VirtualTableManager virtualTableManager = new VirtualTableManager();
    private StackTableManager stackTableManager = new StackTableManager();
    Font font = new Font("Courier", Font.PLAIN, 10);
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AX2;
    private javax.swing.JLabel AX3;
    private javax.swing.JLabel IP;
    private javax.swing.JLabel IP1;
    private javax.swing.JTextArea InOut;
    private javax.swing.JLabel MODE;
    private javax.swing.JLabel PI;
    private javax.swing.JLabel PTR;
    private javax.swing.JLabel SF;
    private javax.swing.JLabel SF1;
    private javax.swing.JLabel SI;
    private javax.swing.JLabel SPTR;
    private javax.swing.JTable StackTable;
    private javax.swing.JLabel TI;
    private javax.swing.JLabel TIMER;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JButton loadAndSyntax;
    private javax.swing.JLabel memory;
    private javax.swing.JLabel memory1;
    private javax.swing.JLabel memory2;
    private javax.swing.JPanel memoryPanel;
    private javax.swing.JTable memoryTable;
    private javax.swing.JLabel processor;
    private javax.swing.JLabel processor1;
    private javax.swing.JPanel processorPanel;
    private javax.swing.JPanel processorPanel1;
    private javax.swing.JButton randomButton;
    private javax.swing.JTextField showIP;
    private javax.swing.JTextField showMode;
    private javax.swing.JTextField showPI;
    private javax.swing.JTextField showPTR;
    private javax.swing.JTextField showSF;
    private javax.swing.JTextField showSI;
    private javax.swing.JTextField showSP;
    private javax.swing.JTextField showSPTR;
    private javax.swing.JTextField showTI;
    private javax.swing.JTextField showTIMER;
    private javax.swing.JTextField showVirtualIP;
    private javax.swing.JTextField showVirtualSF;
    private javax.swing.JTextField showVirtualSP;
    private javax.swing.JButton step;
    private javax.swing.JTable virtualMemoryTable;
    // End of variables declaration//GEN-END:variables

}
